<template>
	<view class="box">
		<view class="map">
			<u-input v-model="value" :type="type" :border="border" @click="inputHandle" />
			<map @tap="clickHandle" id="map" :latitude="latitude" :longitude="longitude" :markers="markers"></map>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: uni.getStorageSync('address') ? uni.getStorageSync('address') : '',
				type: 'text',
				border: true,
				latitude: '',
				longitude: '',
				weizhi:[],
				markers: [{
					latitude: '',
					longitude: '',
					iconPath: '../../static/images/daohang.png'
				}],
			}
		},
		methods: {
			frame() {
				console.log("frame==================")
				uni.chooseLocation({
					success: res => {
						console.log('res==============', res)
						console.log('res==============', res.address)
						console.log('res==============', res.errMsg)
						this.latitude = res.latitude;
						this.longitude = res.longitude;
						this.value = res.address;
						this.markers[0].latitude = res.latitude;
						this.markers[0].longitude = res.longitude;
						this.markers[0].iconPath = '../../static/imgs/map.png';
					}
				});
		
			},
			onLoadHadnle() {
				console.log("onLoadHadnle==================")
				uni.getLocation({
					type: 'wgs84',
					success: res => {
						this.longitude = res.longitude;
						this.latitude = res.latitude;
						this.markers[0].latitude = res.latitude;
						this.markers[0].longitude = res.longitude;
						this.markers[0].iconPath = '../../static/imgs/map.png';
					}
				});
			},
			inputHandle(e) {
				console.log("inputHandle==================")
				this.frame();
			},
			clickHandle(e) {
				console.log("clickHandle==================")
				this.frame();
			}
		},
		created() {
			this.onLoadHadnle();
		},
		onBackPress(options) {
			console.log("onBackPress==================")
			this.weizhi.push(this.latitude)
			this.weizhi.push(this.longitude)
			this.weizhi.push(this.value)
			console.log('options',this.weizhi)
		    // 这里可以自定义返回逻辑，比如下面跳转其他页面
		   uni.redirectTo({
		      url: '/pages/wanshan/wanshan?address='+this.weizhi
		   })
		    // return true 表示禁止默认返回
		   return true;
		},
	}
</script>

<style lang="scss" scoped>
	.box {
		height: 100vh;

		.map {
			width: 100%;
			height: 100%;
			map {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
